package com.neouton.crm.refundRecords.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neouton.annotation.SystemOperationLogs;
import com.neouton.common.util.PageUtil;
import com.neouton.common.util.ResponseAPI;
import com.neouton.crm.refundRecords.entity.RefundProgressInfoVO;
import com.neouton.crm.refundRecords.service.RefundProgressService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 退款进展表
 *
 */
@RestController
@RequestMapping("refundprogress")
public class RefundProgressController {

    @Resource
    private RefundProgressService refundProgressService;


    /**
     * 列表信息查询
     *
     * @param pageNum
     * @param pageSize
     * @param entity
     * @return
     */
    @PostMapping("list/{pageNum}/{pageSize}")
    public ResponseAPI list(@PathVariable(value = "pageNum") int pageNum,
                            @PathVariable(value = "pageSize") int pageSize,
                            @RequestBody RefundProgressInfoVO entity) {
        IPage<RefundProgressInfoVO> page = new Page<>(pageNum, pageSize, true);
        PageUtil<RefundProgressInfoVO> result = refundProgressService.queryPage(page, entity);
        return ResponseAPI.successData(result);
    }

    /**
     * 获取进展详情
     *
     * @param id
     * @return
     */
    @GetMapping(value = "getProgressInfo/{id}")
    public ResponseAPI getProgressInfo(@PathVariable("id") Integer id) {
        List<RefundProgressInfoVO> result = refundProgressService.getProgressInfo(id);
        return ResponseAPI.successData(result);
    }

    /**
     * 数据保存
     *
     * @return
     */
    @PostMapping(value = "save")
    public ResponseAPI save(@RequestBody RefundProgressInfoVO returnedMoneyProgress) {
        refundProgressService.saveRefundProgress(returnedMoneyProgress);
        return ResponseAPI.successMes("保存成功");
    }

    @PostMapping(value = "saveComments")
    public ResponseAPI saveComments(@RequestBody List<RefundProgressInfoVO> voList) {
        refundProgressService.saveComments(voList);
        return ResponseAPI.successMes("保存成功");
    }

    /**
     * 回款进展表：数据修改
     */
    @SystemOperationLogs
    @RequestMapping("update")
    public ResponseAPI update(@RequestBody RefundProgressInfoVO entity,
                              @RequestHeader(value = "token", required = false) Integer token) {
        refundProgressService.updateRefundProgressById(entity);
        return ResponseAPI.successMes("修改模型数据成功");
    }

    /**
     * 删除接口
     *
     * @param id
     * @return
     */
    @SystemOperationLogs
    @GetMapping("/delete/{id}")
    public ResponseAPI delete(@PathVariable("id") Integer id) {
        if (id == null) {
            return ResponseAPI.error("参数错误");
        }
        return ResponseAPI.successData(refundProgressService.deleteRefundProgressById(id));
    }
}
